package com.supor.md_video.adapter;

import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.android.baseconfig.base.GlideApp;
import com.android.baseconfig.base.GlideRequest;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
//import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.supor.aiot.common.helper.GlobalDataCache;
import com.supor.aiot.common.utils.BitmapUtil;
import com.supor.aiot.common.utils.NotNullUtils;
import com.supor.aiot.common.utils.UserAvaUtils;
import com.supor.md_video.R;
import com.supor.md_video.entity.VideoItemInfoBean;
import com.supor.md_video.tools.NumberUtils;

import java.util.List;

import jp.wasabeef.glide.transformations.BlurTransformation;

public class VideoListViewAdapter extends BaseQuickAdapter<VideoItemInfoBean,
        BaseViewHolder> {
    public static final String TAG = "VideoListViewAdapter";

    public VideoListViewAdapter(List<VideoItemInfoBean> datas) {
        super(R.layout.item_video_list, datas);
        addChildClickViewIds(R.id.ll_comm, R.id.ll_sub, R.id.ll_show_detail, R.id.ll_share,
                R.id.iv_jump_recipe, R.id.iv_user_ava);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, VideoItemInfoBean item) {
        GlideApp.with(getContext())
                .load(item.getImageVertical())
                .into((ImageView) holder.getView(R.id.iv_cover));
//        GlideApp.with(getContext())
//                .load(item.getImageVertical())
//                .apply(RequestOptions.bitmapTransform(new BlurTransformation()))
//                .into((ImageView) holder.getView(R.id.iv_cover_bg));
        //是否今日新菜，0：是，1：不是
        holder.setGone(R.id.ll_tag_new, item.getIsNew() == 1);
        if (!TextUtils.isEmpty(item.getProductName())) {
            holder.setGone(R.id.tv_tag_device, false);
            holder.setText(R.id.tv_tag_device, NotNullUtils.getNotNullValue(item.getCrmModelName()));
        } else {
            holder.setGone(R.id.tv_tag_device, true);
        }
        if (TextUtils.isEmpty(item.getChefIcon())) {
            holder.setVisible(R.id.fl_ava, false);
        } else {
            holder.setVisible(R.id.fl_ava, true);
            UserAvaUtils.getAvaRequest(getContext(), item.getChefIcon()).into((ImageView) holder.getView(R.id.iv_user_ava));
        }
//        BitmapUtil.loadLocal(getContext(), item.getYbUserImage(), holder.getView(R.id.iv_user_ava));

        ((TextView) holder.getView(R.id.tv_video_title)).setText(item.getRecipeName());
        ((TextView) holder.getView(R.id.tv_video_detail)).setText(item.getRecipeContent());
        ((TextView) holder.getView(R.id.tv_sub_num)).setText(NumberUtils.formatNum(item.getFavoriteCount()));
        ((TextView) holder.getView(R.id.tv_comm_num)).setText(NumberUtils.formatNum(item.getReplyCount()));
        ((TextView) holder.getView(R.id.tv_share_num)).setText(NumberUtils.formatNum(item.getShareCount()));
        holder.setBackgroundResource(R.id.iv_sub, item.getFavoriteType() == 1 ?
                R.mipmap.ic_video_list_sub_light : R.mipmap.ic_video_list_sub);
    }
}